home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
121_01
/
tl370.c
< prev
next >
Wrap
Text File
|
1985-08-19
|
22KB
|
876 lines
/*
HEADER: CUG 121.??;
TITLE: tl370 - dumb terminal with file xfer;
VERSION: 1.0;
DATE: 01/05/86;
DESCRIPTION: "TL370 emulates a dumb terminal. Incoming data may be
buffered in memory and written to disk, data may be
transmitted from disk to the modem, or files may be
formally transferred in a `checksum' mode with automatic
handshaking and buffering.
TL370 is a modified version of Telnet v2.3, as distributed
with v1.46 of the BDS C compiler. The modification consists
of the addition of optional XON/XOFF handshaking for file
transmission.";
KEYWORDS: terminal, modem, emulate, file transfer;
SYSTEM: CP/M;
FILENAME: TL370.C;
WARNINGS: "Requires local.c for link.
The checksum file transfer does not follow the XMODEM
protocol.
TL370 assumes that the CP/M console is much faster than the
modem (e.g. a 1200+ baud console with a 300 baud modem).";
SEE-ALSO: CALL.C, TEL.C, TELNET.C;
AUTHORS: Leor Zolman, Leo Kenen, Ken Lonquest;
COMPILERS: BDS-C 1.50;
*/
#define TITLE "BDS Telnet version 2.3 (July 1980)"
/*
Written by Leor Zolman and Leo Kenen
December 1979, March 1980, May 1980, July 1980
This version has been modified to obtain all hardware-
dependent information from bdscio.h, which must contain
the correct hardware specifications for your modem port.
It is also no longer necessary to alter #define statements
in this file to reflect CP/M system size; the "topofmem()"
function is now used to determine the amount of memory
available for the text collection buffer.
If you intend to use this program for high speed
(i.e, greater than 300 baud) data transfers, such as
maybe over RS232 lines between two machines directly,
then the speed of transfer will be limited by the
processors involved instead of the baud rate;
UNDER SUCH CIRCUMSTANCES, A TRANSFER WILL ONLY WORK IF
THESE TWO CONDITIONS ARE MET:
1) The transfer must always performd in BINARY
mode, never in TEXT mode, and
2) The receiving processor must be as fast or
FASTER than the transmitting processor. That
is, a 2 MHz machine may transmit to a 4 MHz
machine at, say, 9600 baud, BUT NOT VICE-
VERSA.
See the write up by Leo for more details than are
presented here.
******************************************
* Telnet assumes that your CP/M console *
* I/O device is much faster than your *
* modem. On a 2MHz 8080, the modem can *
* be receiving at up to 300 baud as long *
* as your console whips along (at the *
* very least) at about 1200. 4 MHz mach- *
* ines might be able to get away with *
* slower terminals, but not much slower. *
******************************************
"Telnet" is a program which interacts with a modem to turn
your microcomputer into a very versatile terminal. Special
commands are entered to the program by typing the character
you designate as "SPECIAL", i.e, some character (such as the
null or ^A ) which you wouldn't be likely to need transmitted,
and then entering the appropriate command letter. Incoming
data may be buffered up in RAM memory and dumped to disk
whenever you desire (via the "o", "d", "c" and "k" commands),
data may be transmitted from disk to modem (via "t" and "a"),
or files can be formally transferred in an alternate
"checksum" mode which handles handshaking and buffering
automatically when interacting with the same program on
the other end of the line. During file transfers, you
may temporarily pause and later resume the transmission
(via the "p" and "r" commands.) There are also various
options you can control (see "n", "7", "h" and "l") to
adapt operation toward the type of file you wish to
transfer. The "q" command closes the output file (if open)
and quits to CP/M. The "s" command displays the status of
the program. "z" clears the console screen. Any other
command letter (such as, for example, "?") causes a list
of legal commands to be displayed.
In order to transmit or receive files in the checksum
mode, both parties must make sure that their modems are
operating in FULL-DUPLEX. When you are in full duplex,
then what you type will NOT come right back at you from the
modem; the only input you see from the modem is the data
transmitted by the machine on the OTHER end of the line.
This program considers "half duplex" to be any situation
in which the data you transmit comes right back at you;
whether it is your modem that is performing the ehoing
or a computer system far away doesn't really matter. In any
case, checksumming and handshaking is not allowed under half-
duplex operation, since erroneous characters would be received.
When you run telnet, it will ask you whether
or not you are in half-duplex, and perform accordingly. If
you switch from half to full or vice-versa while running the
program, use the "h" option to inform telnet of the fact.
To perform checksummed file transfer, a connection must
first be established between the two parties. If both
parties are operating in full duplex, one originating and the
other answering, then telnet will both display what each
types to the console and send it to the modem. If a file
then needs to be transferred, then one user would give the
"t" command (to transmit) and the other would give the "o"
command (to open an output file.) If both users indicate
checksum mode (rather than only one specifing checksum mode
which will abort almost immediatly), then telnet will take
it from there and perform the transfer. If the sender
(transmitter) wants to suspend the transfer temporarily and
continue later, he can use the "p" command. When the receiver
sees that transmission has been suspended (when no data has
been sent for a long time), then HE gives the "p" command also,
and both users may type to each other. When ready to resume,
the "r" command must be given by the RECEIVER first, and
then the sender, to prevent data from being lost.
*/
#include <bdscio.h> /* System, h'ware constants */
#include <hardware.h>
#define SPECIAL 0x18 /* The character you type to
signal a Telnet command
(should be obscure...I use
a "control-x") */
/*
The following #defines need not be changed:
*/
#define ACK 0x06 /* Ascii ACK for handshaking */
#define NAK 0x15
#define EOT 0x04 /* End of transmission */
#define ETX 0x03 /* Abort Transmission */
#define XON 0x11 /* Enable transmission */
#define XOFF 0x13 /* Disable transmission */
/*
External variable declarations:
*/
char rflag; /* receiving file open flag */
char tflag; /* transmitting file open flag */
char shflag; /* ascii(ctrl-S, ctrl-Q) handshaking enabled. */
char chflag; /* checksumming enabled flag */
char cflag; /* text-collection enabled flag */
char pflag; /* pausing flag */
char spflag; /* stripping parity bit flag */
char lflag; /* list device enabled flag */
char nflag; /* recognizing nulls flag */
char fflag; /* true if changing CR-LF's into
just CR when transmitting */
char lastc; /* last char xmitted */
char dodflag; /* true if displaying outging
data */
char didflag; /* true if displaying incoming
data */
char hdflag; /* true if effectively working
in half-duplex */
char abortf; /* true when file I/O aborted */
char rbuf[BUFSIZ]; /* file I/O buffer for incoming
data file */
char tbuf[SECSIZ]; /* sector buffer for file being
transmitted */
char rname[20]; /* name of receiving file */
char tname[20]; /* name of transmitting file */
int rfd, tfd; /* file descriptors */
char *cptr; /* pointer to free space in buf */
unsigned free; /* number of bytes free in buf */
int bcount; /* counts bytes in current block
when checksumming */
int scount; /* Number of sectors
sent/received */
int checksum; /* the checksum value itself */
char timoutf; /* true if time-out happens
while waiting for modem data */
char *i; /* odd-job char pointer */
int dod_sav, did_sav; /* scratch variables */